
#include <dev.h>
#include "pic.h"

/* ------------------------------------------------------------------------- */

#define ram_data	(((uint8 *)&ram_bank)[reg_idx])

/* ------------------------------------------------------------------------- */

typedef struct {
	uint8 second;
	uint8 sec_alarm;
	uint8 minute;
	uint8 min_alarm;
	uint8 hour;
	uint8 hour_alarm;
	uint8 day_of_week;
	uint8 day_of_month;
	uint8 month;
	uint8 year;
	uint8 status_a;
	uint8 status_b;
	uint8 status_c;
	uint8 status_d;
} rtc_ram_t;

/* ------------------------------------------------------------------------- */

static uint8 reg_idx;
static rtc_ram_t ram_bank;

/* ------------------------------------------------------------------------- */

void fastcall rtc_init(void)
{
	ram_bank.status_d = 0x80;
}

void fastcall rtc_index(uint8 reg)
{
	reg_idx = reg;
}

uint8 fastcall rtc_read(void)
{
	write_log("[RTC] read %02X", reg_idx);

	if (reg_idx >= sizeof(ram_bank))
		return 0x00;

	return ram_data;
}

void fastcall rtc_write(uint8 data)
{
	write_log("[RTC] write %02X = %02X", reg_idx, data);

	if (reg_idx >= sizeof(ram_bank))
		return;

	ram_data = data;
}

/* ------------------------------------------------------------------------- */
